package MainGUI;

import Util.CalculationWindown;
import Util.FIRWindow;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;

/**
 *
 * @author Oanh
 */
public class WindowFrame extends JFrame {

    int typeWindow;
    CalculationWindown cal;
    FIRWindow firw;

    public WindowFrame() {
        setBounds(30, 20, 900, 700);
        setResizable(false);
        setVisible(true);
    }

    public WindowFrame(FIRWindow firw) {
        this.firw = firw;
        setBounds(30, 20, 900, 700);
        setResizable(false);
        setVisible(true);
    }
    public void setData(FIRWindow fIRWindow){
        this.firw = fIRWindow;
    }

    public WindowFrame(double wp, double ws, int N, int typeWindow) {
        this.typeWindow = typeWindow;
        cal = new CalculationWindown(wp, ws, N, typeWindow);
        setBounds(30, 20, 900, 700);
        setResizable(false);
        setVisible(true);
    }

    public void setValue(double wp, double ws, int N, int typeWindow) {
        this.typeWindow = typeWindow;
        cal = new CalculationWindown(wp, ws, N, typeWindow);
    }

    @Override
    public void paint(Graphics g) {
        g.setColor(Color.LIGHT_GRAY);
        g.fillRect(0, 0, 900, 700);
        g.setColor(Color.WHITE);
        g.fillRect(70, 100, 300, 240);
        g.fillRect(70, 415, 300, 240);
        g.fillRect(510, 100, 300, 240);
        g.fillRect(510, 415, 300, 240);
        g.setColor(Color.BLACK);

        //window 1
        g.drawString("Ideal Impulse Response", 150, 90);
        g.drawString("hd(n)", 20, 220);
        g.drawRect(70, 100, 300, 240);



        //window2
        g.drawString("Rectangle Window", 600, 90);
        g.drawString("h(n)", 30, 535);
        g.drawRect(70, 415, 300, 240);
//        g.drawLine(70, 595, 370, 595);


        //window 3
        g.drawString("Actual Impulse Response", 150, 405);
        g.drawString("w(n)", 470, 220);
        g.drawRect(510, 100, 300, 240);

        //window 4
        g.drawString("Magnitude Response in dB", 600, 405);
        g.drawString("Decibels", 440, 535);
        g.drawRect(510, 415, 300, 240);


        System.out.println("jhkjahk :" + firw.hdMax);
        System.out.println("jhhk :" + firw.hdMin);


        ///////////////////////////////////////////////////////////////////////
        //ve hd(n)
        double ratio_hd = 200 / (firw.hdMax - firw.hdMin);
        double ratio_hn = 200 / (firw.hnMax - firw.hnMin);
        double ratio_wn = 200 / firw.wnMax;

        int point0_hd = 100 + (int) (firw.hdMax * 1.2 * ratio_hd);
        int point0_hn = 415 + (int) (firw.hnMax * 1.2 * ratio_hn);
        double d = (double)300 / firw.M;
        g.drawLine(70, point0_hd, 370, point0_hd);
        g.drawLine(70, point0_hn, 370, point0_hn);
        g.setColor(Color.BLUE);
        for (int i = 0; i < firw.M-1; i++) {
            g.drawLine((int)((i+1) * d) + 70, point0_hd,(int)( (i+1) * d) + 70, (int) (point0_hd - firw.hd[i] * ratio_hd));
            g.drawOval((int)( (i+1) * d) + 65, (int) (point0_hd - firw.hd[i] * ratio_hd)-5, 10, 10);
            g.drawLine((int)((i+1) * d) + 70, point0_hn, (int)((i+1) * d) + 70, (int) (point0_hn - firw.hn[i] * ratio_hn));
            g.drawOval((int)( (i+1) * d) + 65, (int) (point0_hn - firw.hn[i] * ratio_hn)-5, 10, 10);
            g.drawLine((int)((i+1) * d) + 510, 340,(int)( (i+1) * d) + 510, (int) (340 - firw.w[i] * ratio_wn));
            g.drawOval((int)( (i+1) * d) + 505, (int) (335 - firw.w[i] * ratio_wn), 10, 10);
          
        }
        /////////////////

    }
    
   
}
